<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Import Namespace="LAFDC.DataAccess" %>
<%@ Import Namespace="LAFDC.Logging" %>
<script language="c#" runat="server">
        public static readonly String source = "GetADByPrevID.aspx";
        private String ad = String.Empty;

        protected void Page_Load(object sender, EventArgs e) {
            string prev_id = this.Request.QueryString.Get("prev_id");
            
            FDCLogger.LogEvent("Preparing to retrieve the AD for prev_id " + prev_id, source, 4);

            ConnectionManager cn = new ConnectionManager();
            SqlConnection conn = cn.GetSqlConnection();
            SqlCommand tsql = conn.CreateCommand();
            
            tsql.CommandType = CommandType.Text;
            tsql.CommandText = @"exec getADByPrevID " + "'" + prev_id + "'";
            
            FDCLogger.LogEvent("Preparing to execute SQL statement: " + tsql.CommandText, source, 2);

            conn.Open();

            using (SqlDataReader r = tsql.ExecuteReader())
            {
                while (r.Read())
                {
                    ad=r.GetString(0);
                }
            }
            conn.Close();
            
            FDCLogger.LogEvent("Retrieve AD=" + ad, source, 2);


        }
</script>
<%Response.Write(ad);%>